package day05_api.com.itheima.d1_array;

import java.util.Arrays;
import java.util.Comparator;

public class ArraysDemo2 {
    public static void main(String[] args) {
        Student[] students = new Student[4];
        students[0] = new Student("周芷若", 21, '女', 169.7);
        students[1] = new Student("殷素素", 38, '女', 172.2);
        students[2] = new Student("小昭", 19, '女', 168.5);
        students[3] = new Student("张无忌", 23, '男', 183.5);

//        Arrays.sort(students);

        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
//                return o1.getAge() - o2.getAge();
//                if (o1.getHeight() > o2.getHeight()){
//                    return 1;
//                }else if (o1.getHeight() < o2.getHeight()){
//                    return -1;
//                }
//                return 0;
                return Double.compare(o1.getHeight(),o2.getHeight());
            }
        });
        System.out.println(Arrays.toString(students));
    }
}
